package com.suixinsanren.design.proxy.study.gumballmonitor;

public class SoldState implements State {

    private GumballMachine gumballMachine;

    public SoldState(GumballMachine gumballMachine) {
        this.gumballMachine = gumballMachine;
    }

    @Override
    public void insertQuarter() {
        System.out.println("请稍等，我们已经在给您糖果了");
    }

    @Override
    public void ejectQuarter() {
        System.out.println("抱歉，你已经转动曲柄，不能在退钱");
    }

    @Override
    public void turnCrank() {
        System.out.println("转两圈不会给你带来另一个糖果");
    }

    @Override
    public void dispense() {
        if (gumballMachine.getCount() > 0) {
            gumballMachine.releaseBall();
            gumballMachine.setState(gumballMachine.getNoQuarterState());
        } else {
            System.out.println("哎呀，糖果用完了");
            gumballMachine.setState(gumballMachine.getSoldOutState());
        }
    }

    @Override
    public String toString() {
        return "sold state";
    }
}
